package com.tencent.basic;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;

public class Producer {
    public static void main(String[] args) throws Exception{
        // 创建生产者
        DefaultMQProducer producer = new DefaultMQProducer("producer_order_group");
        // 设置MQ链接
        producer.setNamesrvAddr("127.0.0.1:9876");
        // 启动
        producer.start();
        // 创建消息
        Message message = new Message("delay_topic", "delay_tags", "这是推迟delay消息".getBytes(StandardCharsets.UTF_8));
        // 设置一个推迟时间 推迟10s发送消息
        message.setDelayTimeLevel(3);
        SendResult sendResult = producer.send(message);
        System.out.println(sendResult);
        // 关闭
        producer.shutdown();
    }
}
